#pragam once
#include <random> 
#include <time.h>
#include <iostream>
#include "StdAfx.h"
#include 'PlayGame.h'
#include "ViewStats.h"

using namespace system


int main(int argc, char* argv[])
{
	int xa, xb, MultX, addX, gamePoints,max, middle;
	char x;
	string polynomial;
	gamePoints=0;

	// selecting 2 random numbers between 1 and 10
	srand((int) time(NULL));
	xa = (rand()% 10)+1;
	xb = (rand()% 10)+1;
	// setting up the polynomial equation
	MultX = xa*xb;				//product of first integer and second integer
	addX = xa+xb;				//sum of first integer and second integer
	polynomial = x^2 + addX * x + MultX; 
	lblEquation = polynomial;

	while (timerGame != 0) do
	{
		// checking the answer the students entered
		if (btnSumbit->Click ) then
		{
			if (txtAnswer->Text == " ") then {
				MessageBox::Show("Answer is Empty. Please enter an answer.", "My Application" /* ? */,MessageBoxButtons::OKCancel,MessageBoxIcon::Error); 
			}
			else {
				// check key points to give points
				if (txtAnswer->Text == "(x+ "xa")(x+"xb")"||txtAnswer->Text == "(x+ "xb")(x+"xa")") then {
					gamePoints = gamePoints+10;}
				if (txtAnswer->Text == "x= "xa", "xb || txtAnswer->Text =="x= "xb", "xa) then{
					gamePoints = gamePoints+20;}
				// selecting 2 random numbers between 1 and 10
				srand((int) time(NULL));
				xa = (rand()% 10)+1;
				xb = (rand()% 10)+1;
				// setting up the polynomial equation
				MultX = xa*xb;				//product of first integer and second integer
				addX = xa+xb;				//sum of first integer and second integer
				polynomial = x^2 + addX * x + MultX; 
				PolyEquation = polynomial;
			}
		}
		if(btnClear->Click) then{
			if(MessageBox::Show("Do you want to clear your answer?", "My Application", MessageBoxButtons::YesNo,MessageBoxIcon::Question)==DialogResult::Yes) then{
				txtAnswer == " ";
			}
		}
	}

	timesPlayed = timesPlayed + 1;

	// update all the stats
	for (int i; i < timesPlayed+1; i++)
	{
		accumulatedPoints += accumulated[i];
	}

	mean = accumulatedPoints / timesPlayed;

	//find the middle accumulated point
	middle = timesPlayed / 2;
	if (timesPlayed % 2){
		median = (accumulated[middle] + accumulated[middle+1]) / 2.0;
	}
	else{
		median = accumulated[middle];
	}
	
	median = accumulated[timesPlayed / 2];
	
	// go through accumulated points, find highest one
	max = accumulated[1];
	for (int i=2; i < timesPlayed+1; i++)
	{
		if (accumulated[i]>max){
			max = accumulated[i];
		}
	}
	highestValue = max;


	//open view stats page
	ViewStats^ viewstats = gcnew ViewStats();
	viewstats->Show();
	this->Hide();

	return 0;
}